<?php

class Application_Model_DbTable_Rule extends Zend_Db_Table_Abstract
{

    protected $_name = 'rules';

    protected $_referenceMap = array(
        "UserGroup" => array(
            'columns' => "groups_id",
            'refTableClass' => "Application_Model_DbTable_UserGroup",
            'refColumns'=>"idgroups",
            'onUpdate' => self::RESTRICT,
            'onDelete' => self::CASCADE
        ),
        "Action" => array(
            'columns' => "actions_id",
            'refTableClass' => "Application_Model_DbTable_Action",
            'refColumns'=>"idactions",
            'onUpdate' => self::RESTRICT,
            'onDelete' => self::CASCADE
        )
    );
    
 
    public function fetchDataPermission()
    {
        $select = $this->select();
        $select->from(array('r'=>"rules"), array('allow'=>"r.status"))
               ->join(array('ac'=>"actions"),"r.actions_id=ac.idactions",array("action"=>"ac.action_name"))
               ->join(array('cl'=>"controllers"),"ac.controllers_id=cl.idcontrollers",array("controller"=>"cl.controller_name"))
               ->join(array('md'=>"modules"),"cl.modules_id=md.idmodules",array("module"=>"md.module_name"))
               ->join(array('gr'=>"user_groups"),"r.groups_id=gr.idgroups", array("group"=>"gr.groups_name"))
               ->setIntegrityCheck(false);
        return $this->fetchAll($select);
    }
}

